其他
[Gif代码分享] - Test 82 从圆开始
分享一段OF的练习代码。
所有图形只通过ofDrawCircle绘制而成。
配合 ofSetCircleResolution,调节各种参数,可以获得多种图形变化
Gif:
Video:
https://v.qq.com/txp/iframe/player.html?vid=x0185s3lh7c&width=500&height=375&auto=0
关键代码:
float time,circleR,movingDist,speed,lineWidth;
int num,resolution;
bool colorMode,rotateMode;
int shapeMode;
void setup(){
num = 35;
circleR = 400;
movingDist = 200;
speed = 0.05;
lineWidth = 1;
}
void update(){
time+= speed;
}
void draw(){
for(int i = 0;i < num;i++){
ofNoFill();
ofSetCircleResolution(resolution);
ofSetLineWidth(lineWidth);
float input = ofMap(i,0,num - 1,0,PI/2);
float x = sin(time + i/10.0) * movingDist * (1 - i/(float)num);
float y;
if(rotateMode){
y = 0;
}else{
y = cos(time + i/10.0) * movingDist * (1 - i/(float)num);
}
if(colorMode){
ofSetColor(255,180);
}else{
ofSetColor(ofColor::fromHsb(i/(float)num * 255,255,255,200));
}
float r = sin(input) * circleR;
if(shapeMode == 1){
ofDrawCircle(ofGetWidth()/2 + x,ofGetHeight()/2 + y,r);
}
if(shapeMode == 2){
ofDrawEllipse(ofGetWidth()/2 + x,ofGetHeight()/2 + y,r * sin(ofGetElapsedTimef() + i/50.0),r);
}
if(shapeMode == 3){
ofPushMatrix();
ofTranslate(ofGetWidth()/2,ofGetHeight()/2);
ofRotateY(ofGetFrameNum() * (num - i)/(float)num * speed * 30);
ofDrawCircle(0,0,r);
ofPopMatrix();
}
}
}
配合Kinect ,可以有另一种玩法
Enjoy:)
获取源文件可点击阅读原文